#!/bin/bash

APP=gmall

if [ -n "$2" ] ;then
   do_date=$2
else 
   do_date=`date -d '-1 day' +%F`
fi

load_data(){
    sql=""
    for i in $*; do
        #判断路径是否存在
        hadoop fs -test -e /origin_data/$APP/db/${i:4}/$do_date
        #路径存在方可装载数据
        if [[ $? = 0 ]]; then
            sql=$sql"load data inpath '/origin_data/$APP/db/${i:4}/$do_date' OVERWRITE into table ${APP}.$i partition(dt='$do_date');"
        fi
    done
    hive -e "$sql"
}

case $1 in
    "ods_activity_info_ds")
        load_data "ods_activity_info_ds"
    ;;
    "ods_activity_rule_ds")
        load_data "ods_activity_rule_ds"
    ;;
    "ods_base_category1_ds")
        load_data "ods_base_category1_ds"
    ;;
    "ods_base_category2_ds")
        load_data "ods_base_category2_ds"
    ;;
    "ods_base_category3_ds")
        load_data "ods_base_category3_ds"
    ;;
    "ods_base_dic_ds")
        load_data "ods_base_dic_ds"
    ;;
    "ods_base_provdie_ds")
        load_data "ods_base_provdie_ds"
    ;;
    "ods_base_region_ds")
        load_data "ods_base_region_ds"
    ;;
    "ods_base_trademark_ds")
        load_data "ods_base_trademark_ds"
    ;;
    "ods_cart_info_ds")
        load_data "ods_cart_info_ds"
    ;;
    "ods_coupon_info_ds")
        load_data "ods_coupon_info_ds"
    ;;
    "ods_sku_attr_value_ds")
        load_data "ods_sku_attr_value_ds"
    ;;
    "ods_sku_info_ds")
        load_data "ods_sku_info_ds"
    ;;
    "ods_sku_sale_attr_value_ds")
        load_data "ods_sku_sale_attr_value_ds"
    ;;
    "ods_spu_info_ds")
        load_data "ods_spu_info_ds"
    ;;

    "ods_cart_info_di")
        load_data "ods_cart_info_di"
    ;;
    "ods_comment_info_di")
        load_data "ods_comment_info_di"
    ;;
    "ods_coupon_use_di")
        load_data "ods_coupon_use_di"
    ;;
    "ods_favor_info_di")
        load_data "ods_favor_info_di"
    ;;
    "ods_order_detail_di")
        load_data "ods_order_detail_di"
    ;;
    "ods_order_detail_activity_di")
        load_data "ods_order_detail_activity_di"
    ;;
    "ods_order_detail_coupon_di")
        load_data "ods_order_detail_coupon_di"
    ;;
    "ods_order_info_di")
        load_data "ods_order_info_di"
    ;;
    "ods_order_refund_info_di")
        load_data "ods_order_refund_info_di"
    ;;
    "ods_order_status_log_di")
        load_data "ods_order_status_log_di"
    ;;
    "ods_payment_info_di")
        load_data "ods_payment_info_di"
    ;;
    "ods_refund_payment_di")
        load_data "ods_refund_payment_di"
    ;;
    "ods_user_info_di")
        load_data "ods_user_info_di"
    ;;
    "all")
        load_data "ods_activity_info_ds" "ods_activity_rule_ds" "ods_base_category1_ds" "ods_base_category2_ds" "ods_base_category3_ds" "ods_base_dic_ds" "ods_base_provdie_ds" "ods_base_region_ds" "ods_base_trademark_ds" "ods_cart_info_ds" "ods_coupon_info_ds" "ods_sku_attr_value_ds" "ods_sku_info_ds" "ods_sku_sale_attr_value_ds" "ods_spu_info_ds" "ods_cart_info_di" "ods_comment_info_di" "ods_coupon_use_di" "ods_favor_info_di" "ods_order_detail_di" "ods_order_detail_activity_di" "ods_order_detail_coupon_di" "ods_order_info_di" "ods_order_refund_info_di" "ods_order_status_log_di" "ods_payment_info_di" "ods_refund_payment_di" "ods_user_info_di"
    ;;
esac
